package com.zhong.gang.pda.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.luck.picture.lib.tools.ToastUtils;
import com.zhong.gang.pda.R;
import com.zhong.gang.pda.databinding.DialogIntoTypeBinding;
import com.zhong.gang.pda.ui.action.deliver.DeliverAct;
import com.zhong.gang.pda.ui.main.MainBean;
import com.zhong.gang.pda.ui.action.receive.ReceiveAct;
import com.zhong.gang.applib.base.dialog.BaseDialog;

public class IntoTypeDialog extends BaseDialog<DialogIntoTypeBinding> {
    private int selectDrwable = R.drawable.bg_blue_radia3;
    private int notselectDrwable = R.drawable.bg_blueline_radia3;
    private int selectColor = R.color.white;
    private int notSelectColor = R.color.gray3;
    private int isFa = 0;
    private int id;

    public IntoTypeDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    public int LayoutRes() {
        return R.layout.dialog_into_type;
    }

    @Override
    public void initView() {
        bind.setDialog(this);
    }

    @Override
    public double proportion() {
        return 0.85;
    }

    @Override
    public int Gravity() {
        return Gravity.CENTER;
    }

    public void show(int  id){
        super.show();
        isFa = 0;
        this.id = id;
        bind.shouhuo.setBackgroundResource(notselectDrwable);
        bind.shouhuoTv.setTextColor(context.getResources().getColor(notSelectColor));
        bind.shouhuoIv.setImageResource(R.mipmap.icon_dialog_shou);

        bind.fahuoIv.setImageResource(R.mipmap.icon_dialog_fa);
        bind.fahuo.setBackgroundResource(notselectDrwable);
        bind.fahuoTv.setTextColor(context.getResources().getColor(notSelectColor));
    }

    /**
     * 点击事件
     * @param view
     */
    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.fahuo:
                bind.fahuo.setBackgroundResource(selectDrwable);
                bind.fahuoTv.setTextColor(context.getResources().getColor(selectColor));
                bind.fahuoIv.setImageResource(R.mipmap.icon_dialog_faed);

                bind.shouhuoIv.setImageResource(R.mipmap.icon_dialog_shou);
                bind.shouhuo.setBackgroundResource(notselectDrwable);
                bind.shouhuoTv.setTextColor(context.getResources().getColor(notSelectColor));
                isFa = 1;
                break;
            case R.id.shouhuo:
                bind.shouhuo.setBackgroundResource(selectDrwable);
                bind.shouhuoTv.setTextColor(context.getResources().getColor(selectColor));
                bind.shouhuoIv.setImageResource(R.mipmap.icon_dialog_shoued);

                bind.fahuoIv.setImageResource(R.mipmap.icon_dialog_fa);
                bind.fahuo.setBackgroundResource(notselectDrwable);
                bind.fahuoTv.setTextColor(context.getResources().getColor(notSelectColor));
                isFa = 2;
                break;
            case R.id.cancel:
                dismiss();
                break;
            case R.id.sure:
                if (isFa != 1 && isFa != 2){
                    ToastUtils.s(context,"请选择订单类型");
                }
                if (isFa == 1)
                    DeliverAct.openAct(context,id,true);
                else if (isFa == 2)
                    ReceiveAct.openAct(context,id,true);
                dismiss();
                break;
        }
    }
}
